package com.csw.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

//1、统计班级人数
object Text1 {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()
      .setMaster("local")
      .setAppName("text1")

    val sc: SparkContext = new SparkContext(conf)

    val studentsRDD: RDD[String] = sc.textFile("spark/data/students.txt")

    val clazzsRDD: RDD[(String, Int)] = studentsRDD.map(i=>(i.split(",")(4),1))

    val clazzCountRDD: RDD[(String, Int)] = clazzsRDD.reduceByKey(_+_)

    clazzCountRDD.foreach(println)
  }
}
